﻿using PowerTestController.ViewModes;
using Microsoft.Extensions.DependencyInjection;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using PowerTestController.Communication;

namespace PowerTestController
{
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class MainWindow : Window
    {
        public MainWindow()
        {
            InitializeComponent();
            this.DataContext = new MainViewModel();
        }

        protected override void OnClosed(EventArgs e)
        {
            var communication = App.Current.Services.GetRequiredService<SerialPortCommunication>();
            if (communication.IsConncet)
            {
                communication.DisposeSerialPort();
            }
            base.OnClosed(e);
        }

        private void ComboBox_DropDownOpened(object sender, System.EventArgs e)
        {
            if (DataContext is MainViewModel viewModel)
            {
                viewModel.RefreshPortList();
            }
        }
    }
}